package com.bodu.system.controller;

import com.bodu.core.common.AbstractCommonController;
import com.bodu.core.entity.ParamReq;
import com.bodu.core.entity.result.PageResult;
import com.bodu.core.entity.result.Result;
import com.bodu.global.annon.TraceLog;
import com.bodu.global.security.LoginUserUtil;
import com.bodu.system.entity.request.CronTriggersSynchroTimeRequest;
import com.bodu.system.entity.vo.CronTriggersSynchroTimeVo;
import com.bodu.system.service.CronTriggersSynchroTimeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* 定时任务执行时间 API
* @author Administrator
*/
@Api(tags = "定时任务执行时间 API")
@RestController
@RequestMapping("/cronTriggersSynchroTime")
public class CronTriggersSynchroTimeController extends AbstractCommonController<CronTriggersSynchroTimeService, CronTriggersSynchroTimeRequest, CronTriggersSynchroTimeVo>{

    @Autowired
    private CronTriggersSynchroTimeService cronTriggersSynchroTimeService;

    @TraceLog()
    @GetMapping("{id}")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(cronTriggersSynchroTimeService, id);
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("保存定时任务执行时间")
    public Result<Integer> save(@RequestBody CronTriggersSynchroTimeRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.save(cronTriggersSynchroTimeService, request);
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新定时任务执行时间")
    public Result<Integer> update(@RequestBody CronTriggersSynchroTimeRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.update(cronTriggersSynchroTimeService, request);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("定时任务执行时间-查询")
    public Result<List<CronTriggersSynchroTimeVo>>listPage(@RequestBody ParamReq req) {
        req.setManagerDept(LoginUserUtil.getPrincipal().getManagerDept());
        return super.listPage(cronTriggersSynchroTimeService, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("定时任务执行时间-统计")
    public Result<Integer> countPage(@RequestBody ParamReq req) {
        req.setManagerDept(LoginUserUtil.getPrincipal().getManagerDept());
        return super.countPage(cronTriggersSynchroTimeService, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("定时任务执行时间-分页数据")
    public Result<PageResult> page(@RequestBody ParamReq<CronTriggersSynchroTimeRequest> req) {
        req.setManagerDept(LoginUserUtil.getPrincipal().getManagerDept());
        return super.page(cronTriggersSynchroTimeService, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除定时任务执行时间")
    public Result<Integer> delete(@PathVariable("id") Long id) {
        return super.delete(cronTriggersSynchroTimeService, id);
    }

    @TraceLog()
    @ApiOperation("批量删除定时任务执行时间")
    @DeleteMapping("{ids}")
    public Result<Integer> batchDelete(List<Long> ids) {
        return super.batchDelete(cronTriggersSynchroTimeService, ids);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }

}
